package com.example.service.impl;

import com.example.mapper.UserMapper;
import com.example.service.UserService;
import com.example.pojo.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * @version 1.0
 * @Author wql
 * @Date 2024/5/30
 * @Description
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    HttpServletRequest request;
    @Autowired
    private UserMapper userMapper;
    //自动装配RabbitTemplate模板对象
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    public void register(User user) {
        try {
            user.setRegisterUrl(request.getRequestURI());
            userMapper.insert(user);
            //注册成功
            //向交换机发送消息
            this.rabbitTemplate.convertAndSend("Register.exchange","",user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
